package claybird.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.HttpServletBean;
import org.springframework.web.servlet.ModelAndView;

import claybird.dao.PersonneDao;
import claybird.dom.Person;

@Controller
public class PersonneEditController {

	@Autowired PersonneDao personneDao;
	@Autowired PersonneController personneController;
	
	@RequestMapping("/personne/Submit")
	public ModelAndView submitUser(@ModelAttribute Person personne){
		
		personneDao.merge(personne);
		return personneController.showUser();
	}
	

    @ModelAttribute
    public Person findPersonne(@RequestParam(value = "id", required = false)Long id,@RequestParam(value = "guest", required = false)Boolean isGuest){
    	Person result = personneDao.find(id);
    	if(isGuest!=null){
    		result.setGuest(isGuest);
    	}else{
    		result.setGuest(false);
    	}
        return  result;
    }
}
